package com.caipos.actor.common.data.rule;

import com.caipos.actor.common.data.HasVersion;
import com.caipos.actor.common.data.id.RuleChainId;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class RuleChainMetaData implements HasVersion {

    private RuleChainId ruleChainId;

    private Long version;

    private Integer firstNodeIndex;

    private List<RuleNode> nodes;

    private List<NodeConnectionInfo> connections;

    private List<RuleChainConnectionInfo> ruleChainConnections;

    public void addConnectionInfo(int fromIndex, int toIndex, String type) {
        NodeConnectionInfo connectionInfo = new NodeConnectionInfo();
        connectionInfo.setFromIndex(fromIndex);
        connectionInfo.setToIndex(toIndex);
        connectionInfo.setType(type);
        if (connections == null) {
            connections = new ArrayList<>();
        }
        connections.add(connectionInfo);
    }
}
